% FName(1).name = '10x90_new_05Hz_7kV_Rampedsquare_25kVs_2022_05_11_1140.txt';
% FName(2).name = '10x90_old_05Hz_7kV_Rampedsquare_25kVs_2022_05_11_1202.txt';
% FName(3).name = '20x60_new_05Hz_7kV_Rampedsquare_25kVs_2022_05_11_1245.txt';
% FName(4).name = '20x60_old_05Hz_7kV_Rampedsquare_25kVs_2022_05_11_1223.txt';
% FName(1).name = '10x60_EUP_FR3_00_05Hz_7kV_Rampedsquare_25kVs.txt';
% FName(2).name = '20x60_EUP_FR3_00_05Hz_7kV_Rampedsquare_25kVs.txt';
% FName(3).name = '10x60_EUP_FR3_85_05Hz_7kV_Rampedsquare_25kVs.txt';
% FName(4).name = '20x60_EUP_FR3_85_05Hz_7kV_Rampedsquare_25kVs.txt';
% FName(1)s.name = '20x60_EUP_FR3_00_05Hz_7kV_Stepinput.txt';
% FName(2).name = '20x60_EUP_FRB_00_05Hz_10kV_Stepinput.txt';
% FName(1).name = '20x60_EUP_FR3_00_05Hz_7kV_Rampedsquare_25kVs.txt';
% FName(2).name = '20x60_EUP_FRB_00_05Hz_10kV_Rampedsquare_36kVs.txt';
% legendText = {length(FName), 1};
% for i = 1: length(FName)
% % [Time, Volt, Force, Disp, Trigger] = importfile_strainRaw(['raw_', fName]);
% [SF_strain, SF_force] = importfile_strain(fName);
% % Volt = correctTimedelay(Volt);
% plot(SF_strain, SF_force, '.-')
% legendText{i} = [fName(1:5), ' ', fName(11:13), ' ', fName(7:9), ' ', fName(15:16), '% air'];
TargetForce = [0: 2: 40];
smoothingFactor = exPara.sampleFreq/10;
numForceSteps = exPara.forceMax/exPara.forceStep + 1;
Data(1: length(FName), 1: numForceSteps) =...
struct('strain_raw', zeros(exPara.inputRepeat, 1), 'strain', 0, 'force', 0);
% if strcmp(fName, '20x60_EUP_SIL_85_05Hz_7kV_Stepinput.txt')
if contains(fName, 'Step')
exPara.rampTime = exPara.rampTime_step;
elseif contains(fName, 'Ramp')
exPara.rampTime = exPara.rampTime_ramp;
exPara.rampTime = exPara.rampTime_step;
disp('ramping method is not specified')
% [Time, Volt, Force, Disp, Trigger] = importfile_strainRaw(['raw_', fName]);
[Time, Volt, Force, Disp] = importfile_strainRaw_Johannes(['raw_', fName]); % Johannes
% [SF_strain, SF_force] = importfile_strain(fName);
% Disp = -Disp*exPara.kD;
Volt = correctTimedelay(Volt);
Disp_fil = medfilt1(Disp, smoothingFactor);
Force_fil = medfilt1(Force, smoothingFactor);
ylabel('applied force [N]')
plot(Time, Disp_fil, 'k-')
ylabel('displacement [mm]')
if length(Time) <= j * exPara.sampleFreq * exPara.inputRepeat / exPara.inputFreq
disp(['end at', num2str((j-1-1)*exPara.forceStep), 'N'])
Data(i, j) = detectStrain_cnv(Time, Force_fil, Disp_fil, (j-1)*exPara.forceStep, exPara, 0);
% title([fName(4:4), ' ', fName(18:20), ' ', fName(22:25)])
for j = 1: numel(TargetForce)
targetForce = TargetForce(j);
idx0 = fix(targetForce/exPara.forceStep*1/exPara.inputFreq*exPara.inputRepeat*exPara.sampleFreq) + 1;
idx1 = idx0 - 1 + fix(1/exPara.inputFreq*exPara.inputRepeat*exPara.sampleFreq);
disp(['end at', num2str(TargetForce(j-1)), 'N'])
plot(Time(idx0:idx1), Volt(idx0:idx1))
% legend('real input', 'ref input for TF', 'output', "Location", "northoutside", "Orientation","horizontal")
plot(Time(idx0:idx1), Disp(idx0:idx1))
plot(Time(idx0:idx1), Disp_fil(idx0:idx1), 'k-', 'LineWidth', 2)
ylabel('displacement [mm]')
% xlim([Time(idx0) - 5/targetFreq, Time(idx0) + 5/targetFreq])
title([num2str(targetForce), 'N'])
detectStrain_cnv(Time, Force_fil, Disp_fil, targetForce, exPara, 1);
end
fName = 'Fm40_ns_21nc_4_r10.txt'
ramping method is not specified
fName = 'Fm40_ns_21nc_4_r11.txt'
ramping method is not specified
fName = 'Fm40_ns_21nc_4_r12.txt'
ramping method is not specified
fName = 'Fm40_ns_21nc_4_r3.txt'
ramping method is not specified
fName = 'Fm40_ns_21nc_4_r4.txt'
ramping method is not specified
fName = 'Fm40_ns_21nc_4_r5.txt'
ramping method is not specified
fName = 'Fm40_ns_21nc_4_r6.txt'
ramping method is not specified
fName = 'Fm40_ns_21nc_4_r7.txt'
ramping method is not specified
fName = 'Fm40_ns_21nc_4_r8.txt'
ramping method is not specified
fName = 'Fm40_ns_21nc_4_r9.txt'
ramping method is not specified
% legendText{i} = [fName(4:4), ' ', fName(18:20), ' ', fName(22:25)];
legendText{i} = fName; % Johaness
Colors = turbo(length(FName)+1);
% height_pouch = str2num(fName(4:5))*10^-3;
% width_pouch = str2num(fName(7:8))*10^-3;
% epsilon_film = 3.2; %Dielectric constant of film / Mylar 3.2, BOPP 2.8
% epsilon_0 = 8.85 *10^-12;
% thickness_film = 15*10^-6; %um / Mylar 15um, BOPP 20um
nom = HaPara.width_pouch/(4*HaPara.thickness_film)*(HaPara.epsilon_0*HaPara.epsilon_film*(exPara.voltMax*10^3)^2);
figure(2) % force - strain plot
h2(i) = plot([Data(i, :).strain], [Data(i, :).force], '.-', 'Color', Colors(i, :));
plot([Data(i, :).strain_raw], repmat([Data(i, :).force], exPara.inputRepeat, 1), '.', "MarkerEdgeColor", Colors(i, :), 'MarkerSize', 20)
legend(h2, legendText, "Interpreter", "none")
figure(3) % force - strain plot with normalization
h3(i) = plot([Data(i, :).strain]/(HaPara.height_pouch*1e3*HaPara.number_pouch)*100, [Data(i, :).force]/nom, '.-', 'Color', Colors(i, :));
plot([Data(i, :).strain_raw]/(HaPara.height_pouch*1e3*HaPara.number_pouch)*100, repmat([Data(i, :).force]/nom, 4, 1), '.', "MarkerEdgeColor", Colors(i, :), 'MarkerSize', 20)
ylabel('normalized force [-]')
legend(h3, legendText, "Interpreter", "none")
function Out = correctTimedelay(Data)
Out = [Data(2:end); Data(end)];
function Out = detectStrain(Time, Force, Disp, targetForce, exPara, flagPlot)
samplesPerVolt = exPara.sampleFreq/exPara.inputFreq; % num samples per volt
samplesPerForceStep = samplesPerVolt * exPara.inputRepeat; % num samples per displacement step
i = targetForce/exPara.forceStep + 1;
startIndex = (i - 1)*samplesPerForceStep + 1;
endIndex = i*samplesPerForceStep;
Out.force = -mean(Force(startIndex: endIndex));
Ind_max = zeros(exPara.inputRepeat, 1);
Ind_min = zeros(exPara.inputRepeat, 1);
Val_max = zeros(exPara.inputRepeat, 1);
Val_min = zeros(exPara.inputRepeat, 1);
for j = 1: exPara.inputRepeat
startIndex2 = startIndex + (j - 1)*samplesPerVolt;
midIndex2 = startIndex2 + (1/2)*samplesPerVolt;
endIndex2 = (startIndex - 1) + j*samplesPerVolt;
[Val_max(j), Ind_max(j)] = max(Disp(startIndex2: midIndex2));
[Val_min(j), Ind_min(j)] = min(Disp(midIndex2: endIndex2));
Ind_max(j) = Ind_max(j) + startIndex2 - 1;
Ind_min(j) = Ind_min(j) + midIndex2 - 1;
plot(Time(Ind_min(j)), Disp(Ind_min(j)), 'bo', "LineWidth", 2)
plot(Time(Ind_max(j)), Disp(Ind_max(j)), 'ro', 'LineWidth', 2)
Out.strain_raw = Val_max - Val_min;
Out.strain = mean(Out.Strain_raw);
function out = detectStrain_cnv(Time, Force, Disp, targetForce, exPara, flagPlot)
spc= exPara.sampleFreq/exPara.inputFreq;
spf = spc * exPara.inputRepeat; % num samples per displacement step
i = targetForce/exPara.forceStep + 1;
startIndex = (i - 1)*spf + 1;
% endIndex = i*samplesPerForceStep;
max_stroke = zeros(exPara.inputRepeat, 1);
min_stroke = zeros(exPara.inputRepeat, 1);
rawStroke = zeros(exPara.inputRepeat, 1);
force = zeros(exPara.inputRepeat, 1);
rdr = exPara.rampTime*exPara.inputFreq; % ramp delay ratio in a cycle
for j = 1: exPara.inputRepeat
ind_min_start = fix(startIndex + (hold - 0.01)*spc);
ind_min_end = fix(startIndex + (hold + 0.00)*spc);
ind_min_start = fix(startIndex + (hold - 0.01)*spc +spc*(j-1));
ind_min_end = fix(startIndex + (hold + 0.00)*spc +spc*(j-1));
ind_max_start = fix(startIndex + (hold + rdr + hold/2 + 0.01)*spc +spc*(j-1));
ind_max_end = fix(startIndex + (hold + rdr + hold/2 + 0.02)*spc +spc*(j-1));
max_stroke(j)=mean(Disp(ind_max_start: ind_max_end));
min_stroke(j)=mean(Disp(ind_min_start: ind_min_end));
force(j) = -mean(Force(ind_min_start: ind_min_end));
rawStroke(j)= max([0, max_stroke(j) - min_stroke(j)]);
plot([Time(ind_min_start), Time(ind_min_end)], [min_stroke(j), min_stroke(j)], 'bx-', "LineWidth", 2)
plot([Time(ind_max_start), Time(ind_max_end)], [max_stroke(j), max_stroke(j)], 'rx-', "LineWidth", 2)
out.strain_raw = rawStroke;
out.strain = mean(rawStroke);
% out.force = mean(force);
alpha0=0.2415; %alpha0 is constant with optimal filling
Alpha = linspace(alpha0,pi/2-0.01,100);
Force = cos(Alpha)./(1-cos(Alpha));
A = (alpha0 - sin(alpha0)*cos(alpha0))/alpha0^2;
Strain = 1 - alpha0/sin(alpha0).*(1+sqrt(A).*(sin(Alpha) - Alpha)./(sqrt(Alpha - sin(Alpha).*cos(Alpha))));
plot(Strain*100, Force, '--', "DisplayName", 'model')